package com.android.delivery.activity

import android.content.Context
import android.content.Intent
import android.widget.FrameLayout
import androidx.recyclerview.widget.RecyclerView
import com.android.delivery.R
import com.android.delivery.adapter.siji.OrderAdapter
import com.android.delivery.api.ApiService
import com.android.delivery.base.BaseListActivity
import com.android.delivery.callback.DialogCallback
import com.android.delivery.callback.LzyResponse
import com.android.delivery.entity.Logistics
import com.android.delivery.util.DensityUtil
import com.lzy.okgo.model.Response

/**
 * @author: mqwang
 * @create: 2/10/21 12:07 AM
 * @Description: 即将到达
 */
class SendSoonListActivity : BaseListActivity<Logistics>() {

    private val addrAdapter: OrderAdapter by lazy {
        OrderAdapter()
    }

    companion object {
        fun self(context: Context) {
            val intent = Intent(context, SendSoonListActivity::class.java)
            context.startActivity(intent)
        }
    }

    override fun bindRecyclerView(recLv: RecyclerView?) {
        addrAdapter.setType(1)
        recLv!!.adapter = addrAdapter
        setMainTitle("即将到达")

        val margin = DensityUtil.dp2px(12f)
        (recLv.layoutParams as FrameLayout.LayoutParams).setMargins(margin, margin, margin, margin)
        recLv.setBackgroundResource(R.drawable.bg_common)
    }

    override fun loadData(page: Int, pageCount: Int) {
        ApiService.location_order_transporting(this, page, object : DialogCallback<LzyResponse<Logistics>>() {
            override fun onSuccess(response: Response<LzyResponse<Logistics>>?) {
                val records = response!!.body().data.records
                onGetDataSuc(records)
            }
        })
    }

    override fun getData(): MutableList<Logistics> {
        return addrAdapter.data
    }

    override fun bindData(isRefresh: Boolean, list: MutableList<Logistics>?) {
        when (isRefresh) {
            true -> {
                addrAdapter.setNewData(list)
            }
            false -> {
                addrAdapter.addData(list!!)
            }
        }
    }
}